package com.MainXML;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

public abstract class InternetParser {
	
	protected int resultCode;
	protected String urlReturnStr;
	protected String urlStr;

	public InternetParser(String urlString) throws IOException
	{
		resultCode = 0;
		urlReturnStr = "";
		urlStr = urlString;
		refresh();
	}
	
	public void refresh() throws IOException
	{
		URL url = new URL(urlStr);
		
		HttpURLConnection con = (HttpURLConnection)url.openConnection();
		//BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
		BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "EUC-KR"));
		
		resultCode = con.getResponseCode();
		
		
		if(resultCode != 200)
		{
			throw new IOException();
		}
		while(true)
		{			
			String readStr = br.readLine();
			if(readStr == null)
				break;
			urlReturnStr = urlReturnStr +"\r\n"+ readStr;			
		}
	}
	
	abstract public ArrayList<String> parser();
}
